package com.xll.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xll.entity.Kidney;
import com.xll.mapper.KidneyMapper;
import com.xll.service.KidneyService;
import com.xll.utils.PageResult;
import com.xll.utils.QueryInfo;
import com.xll.utils.Result;
import com.xll.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class KidneyServiceImpl implements KidneyService {
    @Autowired
    private KidneyMapper kidneyMapper;
    @Override
    public Result delete(Long id) {
        kidneyMapper.delete(id);
        return Result.success("肾脏检查记录删除成功");
    }

    @Override
    public Result update(Kidney kidney) {
        kidneyMapper.update(kidney);
        return  Result.success("肾脏检查记录更新成功");
    }

    @Override
    public Result findPage(QueryInfo queryInfo) {
        queryInfo.setQueryString(SecurityUtils.getUsername());
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<Kidney> page = kidneyMapper.findPage(queryInfo.getQueryString());
        return Result.success("肾脏检查记录查询成功", new PageResult(page.getTotal(), page.getResult()));
    }

    @Override
    public Result insert(Kidney kidney) {
        kidney.setPeople(SecurityUtils.getUsername());
        kidneyMapper.insert(kidney);
        return  Result.success("肾脏检查记录插入成功");
    }

    @Override
    public List<Kidney> findByName(String people) {
        List<Kidney> byName = kidneyMapper.findByName(people);
        return  byName;
    }
}
